package com.yc.project1.service;

import com.yc.project1.bean.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

/**
 * @author zwei
 * @create 2024-08-08 20:05
 */
@Repository
public class CacheService {
    @Autowired
    private CacheManager cacheManager;
    public void getCache() {
        // 获取名为 "users" 的缓存
        Cache usersCache = cacheManager.getCache("users");
        if (usersCache != null) {
            // 获取缓存中的值
            Account cachedValue = usersCache.get("1", Account.class); // 替换 "someKey" 为实际的缓存键
            if (cachedValue != null) {
                System.out.println("cache中的值为"+cachedValue);
            } else {
                System.out.println("cache中没有值");
            }
        } else {
            System.out.println("users中无值");
        }
    }
}
